#ifndef CANTESTER_H
#define CANTESTER_H

#include <QObject>
#include <QMessageBox>
#include "ControlCAN.h"
#include "canthread.h"

class CanTester : public QObject {
    Q_OBJECT
public:
    explicit CanTester(QObject *parent = nullptr);



    Q_INVOKABLE void sendTestData();
    Q_INVOKABLE void receiveData();

    Q_INVOKABLE void canQmlToCpp(quint16 canBaundRate);
    Q_INVOKABLE void canQmlToCppdeviceIndex(quint16 deviceIndex);

    Q_INVOKABLE bool canOpenDevice();
    Q_INVOKABLE bool canInitDevice();
    Q_INVOKABLE bool canStartDevice();
    Q_INVOKABLE void canCloseDevice();
    Q_INVOKABLE bool canResetDevice();
    Q_INVOKABLE void onBoardInfo(VCI_BOARD_INFO vbi);

    Q_INVOKABLE void canChannel(int channel);
    Q_INVOKABLE void canFrameStandardOrExtend(BYTE type);
    Q_INVOKABLE void canFrameDataOrRemote(BYTE type);
    Q_INVOKABLE void canId0x(QString canId0x);
    Q_INVOKABLE void canSendData(QString canSenddata);

     // 信号连接起来
    Q_PROPERTY(QString rcvCan_Num                READ rcvCan_Num                         NOTIFY rcvCan_NumChanged)
    Q_PROPERTY(QString rcvHw_Version             READ rcvHw_Version                      NOTIFY rcvHw_VersionChanged)
    Q_PROPERTY(QString rcvDr_Version             READ rcvDr_Version                      NOTIFY rcvDr_VersionChanged)
    Q_PROPERTY(QString rcvIr_Version             READ rcvIr_Version                      NOTIFY rcvIr_VersionChanged)

    // 定义封装函数
    QString rcvCan_Num()                 { return _rcvCan_Num; }
    QString rcvHw_Version()              { return _rcvHw_Version; }
    QString rcvDr_Version()              { return _rcvDr_Version; }
    QString rcvIr_Version()              { return _rcvIr_Version; }

    QString versionStr(USHORT ver);

signals:

    void rcvCan_NumChanged                 (QString rcvCan_Num);
    void rcvHw_VersionChanged              (QString rcvHw_Version);
    void rcvDr_VersionChanged              (QString rcvDr_Version);
    void rcvIr_VersionChanged              (QString rcvIr_Version);


private:
    quint16 m_deviceIndex;
    quint16 m_canBaundRate;
    quint16 m_canChannel;
    BYTE m_canFrameStandardOrExtend;   // 0 标准 1 扩展
    BYTE m_canFrameDataOrRemote;       // 0 数据 1 远程
    QString m_canId0x;
    QString m_canSendData;

    CANThread *canthread;

    QString _rcvCan_Num = 1;
    QString _rcvHw_Version = 1;
    QString _rcvDr_Version = 1;
    QString _rcvIr_Version = 1;

    void on_pushButton_clicked();

private slots:


};

#endif // CANTESTER_H
